/**
 * Created by Administrator on 2016/11/28.
 */
$(".form-date").datetimepicker(
    {
      language: "zh-CN",
      weekStart: 1,
      todayBtn: 1,
      autoclose: 1,
      todayHighlight: 1,
      startView: 2,
      minView: 2,
      forceParse: 0,
      format: "yyyy-mm-dd"
    });
/**
 * Created by Administrator on 2016/11/15.
 */
$(function () {
  initDom();
  initEvent();

  $('.add_type_container').hide();
  addNewType();
  closeBtn();
});

function initDom() {

  $("#kinds-content").hide();
  $("#qhTable_project").bootstrapTable({
    url: "http://192.168.59.23:8080/shixiaobao/basedata/projectType/projecttypelist/1/10",// 工程类别数据接口
    onExpandRow: orderGoodsFun
  });
  $(".fixed-table-header table").css("display", "");
  $("#qhTable_project").css("display", "");
  $(".fixed-table-body table").css('margin-top', '0');
  $(".fixed-table-toolbar .fixed-table-container").css({"padding-bottom": "0"});

}
function orderGoodsFun(index, row, detail) {
  console.log("展开行：" + index + "   整行的值是：");
  console.log(row);
  $.getJSON("goods/data.json?", function (response) {
    var htmlStr = template('goodsTplScript', response);
    detail.html(htmlStr);
  });
}
function initEvent() {
  $(".new-project").on("click", function () {
    $('#addTypeName').val('');
    $('.add_type_container').show();
  })
}

function addNewType(){
  $(".add_btn").click(function(){
    var projectType=$("#addTypeName").val();
    var url="http://192.168.59.23:8080/shixiaobao/basedata/projectType";
    $.ajax({
      type:"post",
      data:{projectType:projectType},
      url:url,
      contentType:"application/json;charset=utf-8",
      success:function(data){
        console.log(data);
      },
      error:function(err){
        console.log(err)
      }
    });
    $('.add_type_container').hide();
  })
}

function totalFormatter(value, row, index) {
  return "<button class='btn btn-default' onclick=\"deleteBtn(this)\" >删除</button>";
}

function closeBtn(){
  $('.close_btn').on('click',function(){
    $('.add_type_container').hide();
  })
}
function deleteBtn(btn) {
  // 获取对应ID
  var id=$(btn).parent().parent().children(':first-child').html();
  var url="http://192.168.59.23:8080/shixiaobao/basedata/projectType/"+id;//todo 接口地址
  // 接口
  $.ajax({
    url:url,
    type:"delete",
    success:function(data){
      console.log(data);
    },
    error:function(err){
      console.log(err);
    }
  })
}

function myQueryParams(params) {
  params["pageNum"] = (params.offset / params.limit) + 1;
  params.pageSize = params.limit;
  params.derection = "asc";
  params.sort = "id";

  params.orderCode = $("#orderCode").val() + "";
  return params;
}

function responseHandler(res) {
  sessionStorage.setItem('data',JSON.stringify(res));
  console.log(JSON.parse(sessionStorage.getItem('data')));
  var needData = {
    rows: res.data
  };
  return needData;
}





